"""豆瓣电影知识问答"""
from query_backend.question_classifier import *
from query_backend.answer import *


class KgDemo:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.searcher = AnswerSearch()

    def main(self, sent):
        # answer = '暂时无法识别你的答案，换一种输入试试？'
        # res_classify = self.classifier.classify(sent)
        # if not res_classify:
        #     return answer
        # res_sql = self.searcher.answer_cql(res_classify)
        # final_answers = self.searcher.search(res_sql)
        # if not final_answers:
        #     return answer
        # else:
        #     return '\n'.join(final_answers)
        answer = ''
        res_classify = self.classifier.classify(sent)
        answer += '解析问题：' + str(res_classify) + '\r\n\r\n'
        if not res_classify:
            return answer
        res_sql = self.searcher.answer_cql(res_classify)
        answer += '生成Cypher语句：' + str(res_sql) + '\r\n\r\n'
        final_answers = self.searcher.search(res_sql)
        if not final_answers:
            answer += '未查询到结果'
        else:
            answer += '\r\n'.join(final_answers)

        return answer


if __name__ == '__main__':
    demo = KgDemo()
    while 1:
        question = input('用户:')
        answer = demo.main(question)
        print('小冰:', answer)
